<template>
  <div>
    <Pane>
      <span slot="title">
        <span style="margin-right:20px; ">时间范围</span>
        <el-date-picker
          v-model="date"
          value-format="yyyy-mm-dd HH:MM:SS"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
        <el-button @click="handleClick" type="primary" style="margin-left:20px; ">查询</el-button>
      </span>
      <section slot="content">
        <div class="contain">
          <Charts :options="options" />
        </div>
      </section>
    </Pane>
  </div>
</template>

<script>
import Pane from '@/components/Pane/Pane.vue'
import Charts from '@/components/Charts/Charts.vue'

import { getTotalData } from '@/api/order.js'

export default {
  name: 'GoodsTotal',
  props: {},
  data() {
    return {
      options: {},
      date: ''
    }
  },
  methods: {
    async init() {
      const { xData, orderData, amountData } = await getTotalData()
      // console.log(xData, orderData, amountData)
      this.options = {
        title: {
          text: '数据统计'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        legend: {
          data: ['订单', '销售额', '注册人数', '管理员人数']
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: xData
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '订单',
            type: 'line',
            stack: '总量',
            areaStyle: {},
            data: orderData
          },
          {
            name: '销售额',
            type: 'line',
            stack: '总量',
            areaStyle: {},
            data: amountData
          }
        ]
      }
    },
    handleClick() {
      console.log(this.date)
    }
  },
  created() {
    this.init()
  },
  components: {
    Pane,
    Charts
  }
}
</script>

<style scoped >
.contain {
  width: 100%;
  height: 360px;
  background: #fff;
  margin-top: 30px;
}
</style>
